﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;

namespace Sino.CapacityCloud.Repositories.Models
{

    public class RatingRecord
    {

        [Key()]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public string RatingRecordId { get; set; }

        public string CarrierOrderId { get; set; }

        public string ContractNumber { get; set; }

        public string UserId { get; set; }

        public string CarId { get; set; }

        public string OrderId { get; set; }

        public string Driver { get; set; }

        public string Appraiser { get; set; }

        public string PhoneNumber { get; set; }

        public float Integrity { get; set; }

        public float Timeliness { get; set; }

        public float Attitude { get; set; }

        public float Pricing { get; set; }

        public string Evaluation { get; set; }

        public DateTime Time { get; set; }

        public string Remarks { get; set; }

        public virtual ApplicationUser User { get; set; }

        public virtual Car Car { get; set; }

        public virtual ConfirmedOrder Order { get; set; }

        [NotMapped]
        public double TotalRating
        {
            get
            {
                return new double[]
                {
                    this.Attitude,
                    this.Timeliness,
                    this.Pricing,
                    this.Integrity
                }.Average();
            }
        }

        public RatingRecord()
        {
            this.RatingRecordId = Guid.NewGuid().ToString();
        }

    }

}